package com.googlecode.imanager.core.base;

import com.googlecode.imanager.client.util.Logger;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class DefaultLogger implements Logger {

    private String name;
    
    public DefaultLogger(Class<?> ownerClass) {
        this.name = ownerClass.getName();
    }

    @Override
    public void debug(CharSequence message) {
        System.out.println("DEBUG[" + name + "]: " + message);
    }

    @Override
    public void debug(CharSequence message, Object value) {
        System.out.println("DEBUG[" + name + "]: " + message + ", " + value);
    }

    @Override
    public void error(CharSequence message) {
        error(message, null);
    }

    @Override
    public void error(Throwable e) {
        error("", e);
    }

    @Override
    public void error(CharSequence message, Throwable e) {
        System.err.println("ERROR[" + name + "]: " + message);        
        if (e != null){
            e.printStackTrace(System.err);
        }
    }

    @Override
    public void trace(CharSequence message) {
        System.out.println("TRACE[" + name + "]: " + message);
    }

    @Override
    public void trace(CharSequence message, long miliseconds) {
        System.out.println("TRACE[" + name + "]: " + message + ", " + (miliseconds/1000.0) + " seconds");
    }

    @Override
    public void warning(CharSequence message) {
        System.out.println("WARNING[" + name + "]: " + message);
    }

    @Override
    public void warning(CharSequence message, Throwable e) {
        System.err.println("WARNING[" + name + "]: " + message);
        if (e != null){
            e.printStackTrace(System.err);
        }
    }

}
